# -*-coding:utf-8 -*-
# Author : Mo
# Data : 2022/2/6 15:34
from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import HttpResponse,redirect

class AuthMidddleware(MiddlewareMixin):
    """ 中间件1 """

    # def process_request(self,request):
    #     # 0.排除那些不需要登录就能访问的页面
    #     # request.path_info 获取当前用户请求的URL /login/
    #     if request.path_info in ["/login/", "/image/code/"]:
    #         return
    #
    #     # 1.读取当前访问的用户session信息,如果能读到，说明已登录过，就可以继续向后走。
    #     info_dict = request.session.get("info")
    #     if info_dict:
    #         return
    #
    #     # 2.没有登录过，回到登录页面
    #     return redirect("/login/")
    #
    #     # 如果方法中没有返回值(返回None),继续向后走
    #     # 如果有返回值 HttpResponse,render,redirect
    #     # print("M1.进来了")
    #     # return HttpResponse("无权访问")
    #
    # def process_response(self,request,response):
    #     return response


